# coding=utf-8
import time
import threading
import random

# 创建全局ThreadLocal对象:
local_school = threading.local()

def process_student():
    print 'Hello, %s (in %s)\n' % (local_school.student, threading.current_thread().name)
    n = 0
    while 1:
        n += 1
        if n == 20:
            break
        print time.time(), threading.current_thread().name
        time.sleep(random.random())

def process_thread(name):
    # 绑定ThreadLocal的student:
    local_school.student = name
    process_student()

t1 = threading.Thread(target= process_thread, args=('Alice',), name='Thread-A')
t2 = threading.Thread(target= process_thread, args=('Bob',), name='Thread-B')
t1.start()
t2.start()
t1.join()
t2.join()